package com.paas.form.controller;


import com.paas.common.util.StringUtil;
import com.paas.form.entity.FormApiLogParamEntity;
import com.paas.form.service.IFormApiLogParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.paas.common.util.BeanUtil;
import com.paas.common.model.RestResponse;
import com.paas.common.web.annotion.OperLog;
import com.paas.common.web.controller.BaseController;
import com.paas.common.web.oper.OprLogConstant;


import com.paas.form.entity.FormApiLogEntity;
import com.paas.form.service.IFormApiLogService;

@RestController
@RequestMapping(value = "/form/formApiLog")
@Api(description = "接入日志", tags = "")
public class FormApiLogController extends BaseController {

    @Autowired
    public IFormApiLogService formApiLogService;

    @Autowired
    public IFormApiLogParamService formApiLogParamService;

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存信息", notes = "保存信息")
    @OperLog(operType = OprLogConstant.ADD,operModul = "",operDescribe = "-保存")
    public void save(@RequestBody FormApiLogEntity formApiLogEntity) throws ParseException{
		if(BeanUtil.isNotEmpty(formApiLogEntity)){
			injectUpdateDataAuth(formApiLogEntity);
		}
    	formApiLogService.save(formApiLogEntity);
    }

    @RequestMapping(value = "/saveBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量保存信息", notes = "批量保存信息")
    @OperLog(operType = OprLogConstant.UPDATE,operModul = "",operDescribe = "-批量保存修改")
    public void saveBatch(@RequestBody List<FormApiLogEntity> list) throws ParseException{
		if(list!=null && list.size()>0){
            injectUpdateDataAuth(list);
        }
    	formApiLogService.saveBatch(list);
    }

    @RequestMapping(value = "/delectById",method = RequestMethod.GET)
    @ApiOperation(value = "根据Id删除数据", notes = "根据Id删除数据")
    @OperLog(operType = OprLogConstant.DELETE,operModul = "",operDescribe = "-删除")
    public void delectById(String id){
		if (null != id && !"".equals(id)) {
			FormApiLogEntity formApiLogEntity = new FormApiLogEntity();
			injectUpdateDataAuth(formApiLogEntity);
			formApiLogEntity.setId(id);
			formApiLogService.deleteByEntity(formApiLogEntity);
		}
    }

    @RequestMapping(value = "/deleteBatchByIds",method = RequestMethod.POST)
    @ApiOperation(value = "根据Id批量删除数据", notes = "根据Id批量删除数据")
    @OperLog(operType = OprLogConstant.DELETE,operModul = "",operDescribe = "-批量删除")
    public void deleteBatchByIds(@RequestBody List<String> ids){
		if (null != ids && ids.size() > 0) {
			FormApiLogEntity formApiLogEntity = new FormApiLogEntity();
			injectUpdateDataAuth(formApiLogEntity);
			//formApiLogService.deleteBatchIds(ids);
			formApiLogService.deleteBatchIdsWithPermission(ids,formApiLogEntity);
		}
    }

    @RequestMapping(value = "/queryById",method = RequestMethod.GET)
    @ApiOperation(value = "根据Id查询对象", notes = "根据Id查询对象")
    public FormApiLogEntity queryById(String id){
         FormApiLogEntity bean = formApiLogService.getById(id);
         return bean;
    }

    @RequestMapping(value = "/queryBatchByIds",method = RequestMethod.POST)
    @ApiOperation(value = "根据Id查询对象列表", notes = "根据Id查询对象列表")
    public List<FormApiLogEntity> queryBatchByIds(@RequestBody List<String> ids){
         List<FormApiLogEntity> list = formApiLogService.getBatchByIds(ids);
         return list ;
    }

    @RequestMapping(value = "/queryPage",method = RequestMethod.GET)
    @ApiOperation(value = "模板分页查询", notes = "模板分页查询")
    public IPage<FormApiLogEntity> queryPage(FormApiLogEntity formApiLogEntity, Integer currentPage, Integer pageSize){
    	if (currentPage == null) {
    		currentPage = 1;
    	}
    	if (pageSize == null) {
    		pageSize = 10;
    	}
		injectCheckDataAuth(formApiLogEntity);
    	IPage<FormApiLogEntity> pageBean = formApiLogService.getPage(formApiLogEntity, currentPage, pageSize);
    	return pageBean;
    }

    @RequestMapping(value = "/queryList",method = RequestMethod.GET)
    @ApiOperation(value = "模板查询", notes = "模板查询")
    public List<FormApiLogEntity> queryList(FormApiLogEntity formApiLogEntity){
		injectCheckDataAuth(formApiLogEntity);
    	List<FormApiLogEntity> list = formApiLogService.getList(formApiLogEntity);
        return list;
    }

    @RequestMapping(value = "/getParamByLogId",method = RequestMethod.GET)
    @ApiOperation(value = "根据logId查询请求参数", notes = "根据logId查询请求参数")
    public FormApiLogParamEntity getParamByLogId(String logId){
        FormApiLogParamEntity formApiLogParamEntity = new FormApiLogParamEntity();
        if (StringUtil.isNotEmpty(logId)){
            formApiLogParamEntity  =   formApiLogParamService.queryByLogId(logId);
        }
        return formApiLogParamEntity;
    }
}